package cn.tedu.egmvc2.controller;

import cn.tedu.egmvc2.mapper.AddressMapper;
import cn.tedu.egmvc2.pojo.entity.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;

    @PostMapping("insert")
    public String insert(Address address) {
        addressMapper.insertAddress(address);
        return "插入成功";
    }

    @GetMapping("select")
    public List<Address> select() {
        return addressMapper.selectAddress();
    }

    @GetMapping("delete")
    public String delete(Integer id) {
        addressMapper.deleteAddress(id);
        return "删除成功";
    }

    @PostMapping("update")
    public String update(Address address) {
        addressMapper.updateAddress(address);
        return "更新成功";
    }

    @GetMapping("/selectById/{id}")
    public Address selectById(@PathVariable Integer id) {
        return addressMapper.selectAddressById(id);
    }


}
